(function($){
	 function initAddPhoto() {
	        var but = $('#but_add_photo');
	        but.on('click', function(){
	            var box = $('#bp_photos_box');
	            if($(".paddingTB5").length > 2){
	            	alert('最多上传三张');
	            	return false;
	            }
	            box.append('<div class="input-group paddingTB5"><input type="file" class="form-control" name="q_photos[]"><div class="input-group-addon bg_red cursor_pointer" onclick="$.bpPhotoDel(this)"><i class="fa fa-times"></i></div></div>');
	        });
	    }
	 function formResult(msg, state) {
	        layer.closeAll();
	        if(state == 0) {
	            layer.alert(msg, {icon: 5});
	        } else {
	            layer.confirm('添加成功！', {icon: 6, title:'系统提示', btn: ['确定']}, function(index){
	                location.href = $('#form_add').attr('urlList')
	            });
	        }
	    }
	 $.extend({
	        'bpPhotoDel': function(obj) {
		            if($(".paddingTB5").length < 2){
		            	alert('最少留一个');
		            	return false;
		            }
	            $(obj).parent().remove();
	        }
	    });
    function refreshUser(parame){
        $("select[name='user_id']").html("");
        var html = '';
        for(var i= 0;i < parame.length;i++){
            var data = parame[i];
            html += "<option value='"+data.user_id+"'>"+ data.user_nickname +"</option>";
        }
        $("select[name='user_id']").html(html);
    }
    $(function(){
    	initAddPhoto();
        window.refreshUser = refreshUser;
        window.formResult = formResult;
    	$('#form_add').on('valid.form', function(e, form){
            layer.load();
            form.submit();
        });
        $("input[name='search_user']").change(function() {
            var username = $("input[name='search_user']").val();
            $.ajax({
                type:'POST',
                dataType:'json',
                url:'/manage/questionmanage/searchuser',
                data:{search_user:username},
                success:function (data){
                    refreshUser(data.list);
                }
            })
        });
    });
})(jQuery);